package org.vergil.controller;

import org.springframework.web.bind.annotation.ModelAttribute;
import org.vergil.dto.User;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * Created by vergil on 17-3-29.
 */
public class BaseController {

    protected HttpServletResponse response;
    protected HttpSession session;
    protected HttpServletRequest request;
    protected User user;

    /***
     * 该Controller的所有方法在调用前，先执行此@ModelAttribute方法。
     * 每个请求的方法前获取到session里的user信息
     * @param request
     * @param response
     * @param session
     */
    @ModelAttribute
    public void setReqAndRes(HttpServletRequest request, HttpServletResponse response, HttpSession session){
        this.request = request;
        this.response = response;
        this.session = session;
        User user = (User) session.getAttribute("user");
        if (null != user){
            this.user = user;
        }
    }
}
